import { http } from '../utils/http/index'

// HR用户信息接口
export interface HrUserInfo {
  id: string
  phone: string
  nickName: string
  realName: string
  sex: number
  face: string
  email: string
  birthday: string
  country: string
  province: string | null
  city: string | null
  district: string | null
  description: string
  startWorkDate: string
  graduationYear: number
  role: number
  createdTime: string
  updatedTime: string
  userToken: string | null
  userId: string
  companyId: string
  companyName: string
  peopleSize: string
  financStage: string
  position: string
  bindType: number
  logo: string
  industry: string
  hrSignature: string
  hrTags: string
  showWhichName: number  // 1-昵称 2-真实姓名
}

// 更新公司用户绑定信息请求体
export interface UpdateCompanyUserBindInfoRequest {
  position?: string
  showWhichName?: number
  hrSignature?: string
  hrTags?: string
}

/**
 * 获取HR用户信息（当前登录用户）
 */
export async function getHrUserInfo(): Promise<HrUserInfo> {
  const response = await http.get('/portal/user/getHrUserInfo')
  return response as HrUserInfo
}

/**
 * 根据hrId获取HR用户信息
 */
export async function getHrUserInfoByHrId(hrId: string): Promise<HrUserInfo> {
  const response = await http.get(`/portal/user/getHrUserInfoByHrId?hrId=${hrId}`)
  return response as HrUserInfo
}

/**
 * 更新公司用户绑定信息
 */
export async function updateCompanyUserBindInfo(data: UpdateCompanyUserBindInfoRequest): Promise<void> {
  await http.post('/portal/user/update_company_user_bind_info', data)
}

/**
 * 解除公司绑定
 */
export async function unbindCompany(): Promise<void> {
  await http.post('/portal/user/user_company_unbind', {})
}

// 职位信息接口
export interface JobInfo {
  id: string
  hrId: string
  companyId: string
  jobName: string
  jobType: string
  tags: string
  expYears: string
  edu: string
  beginSalary: number
  endSalary: number
  monthlySalary: number
  city: string
  jobDesc?: string  // 职位描述（纯文本）
  jobDescHtml?: string  // 职位描述（HTML格式）
  address?: string  // 工作地点详细地址
  status: number  // 1-招聘中 2-已关闭 3-违规删除
  violateReason?: string  // 违规原因
  updatedTime?: string  // 更新时间
}

// 获取职位列表请求参数
export interface GetJobListRequest {
  pageNo: number
  pageSize: number
  status: number
}

// 获取职位列表响应
export interface GetJobListResponse {
  totals: number
  totalPages: number
  list: JobInfo[]
}

/**
 * 获取HR职位列表
 */
export async function getHrJobList(data: GetJobListRequest): Promise<GetJobListResponse> {
  const response = await http.post('/portal/job/get_hr_job_list', data)
  return response as GetJobListResponse
}

/**
 * 获取职位详情
 */
export async function getJobDetail(jobId: string): Promise<JobInfo> {
  const response = await http.get(`/portal/job/detail/${jobId}`)
  return response as JobInfo
}

// 提交职位请求参数
export interface SubmitJobRequest {
  id?: string  // 编辑时需要，新增时不需要
  jobName: string
  jobType: string
  expYears: string
  edu: string
  beginSalary: number
  endSalary: number
  monthlySalary: number
  jobDesc: string
  jobDescHtml: string
  tags: string
  city: string
  address: string
  status: number  // 1-招聘中 2-已关闭
}

/**
 * 提交职位（新增或编辑）
 */
export async function submitJob(data: SubmitJobRequest): Promise<void> {
  await http.post('/portal/job/submit', data)
}

